package controller;

import pojo.GoodsSingle;
import pojo.MyTools;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/index")
public class StartServlet extends HttpServlet {
    ArrayList<GoodsSingle> goodslist = null;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = this.getServletContext();
        if(null == context.getAttribute("goodslist")){
            try{
                goodslist = MyTools.getGoods();
            }
            catch (Exception e){
                e.printStackTrace();
            }
            context.setAttribute("goodslist", goodslist);
        }
        // 请求转发到show.jsp
        req.getRequestDispatcher("show.jsp").forward(req, resp);
    }
}
